# -*- coding: utf-8 -*-
# @Time     : 2021/5/6 11:05
# @Author   : pengrenjie
# @Email    : 941257162@.com
# @File     : atm取款机 面向对象.py

#1 分析atm存取款功能
#两个类 ：ATM 用户

#ATM:
# 属性：钱，名称，位置
# 方法：放钱进去，取出atm里面的钱

#用户
#属性 ：账户，密码，账户金额
#方法 ：存钱，取钱，查看金额


class ATM():
   def __init__(self,money,name,location):
       self.money = money
       self.name = name
       self.location = location
   def add_money(self,money):
       print(f"添加金额:{money}")
       self.money += money
   def take_money(self,money):
       print(f"取出金额:{money}")
       self.money -= money


class User():
    def __init__(self,name,passwd,money):
        self.name = name
        self.passwd = passwd
        self.money = money
    def save_money(self,money,atmobj):
        print(f"存入金额:{money}")
        self.money += money
        atmobj.money += money
    def get_money(self,money,atmobj):
        print(f"取出金额:{money}")
        if money <= self.money and money <= atmobj.money:
            self.money -= money
            atmobj.money -= money
        else:
            print("账户或取款余额不足")
    def show_money(self):
        print(f"当前账户余额为:{self.money}")


def Atmenu():
    while 1:
        print("atm".center(30, '*'))
        print("1%s取钱" % ('-' * 20))
        print("2%s存钱" % ('-' * 20))
        print("3%s退出" % ('-' * 20))
        number2 = input("请输入数字:")
        if number2 == '1':
            a = input("请输入取出的金额:")
            if a.isdigit():
               atm.take_money(int(a))
               print(atm.money)
            else:
                 print("输入的不是数字请重新輸入")
        elif number2 == '2':
            b = input("请输入取出的金额:")
            if b.isdigit():
                atm.add_money(int(b))
            else:
                print("输入的不是数字请重新輸入")
        elif number2 == '3':

            break

def Usermenu():
    while 1:
        print("用户".center(30, '*'))
        print("1%s取钱" % ('-' * 20))
        print("2%s存钱" % ('-' * 20))
        print("3%s查询" % ('-' * 20))
        print("4%s退出" % ('-' * 20))
        number2 = input("请输入数字:")
        atm = ATM(10000, "工商银行", "农大")
        if number2 == '1':
            a = input("请输入取出的金额:")
            if a.isdigit():
               user.get_money(int(a),atm)
            else:
                 print("输入的不是数字请重新輸入")
        elif number2 == '2':
            b = input("请输入存入的金额:")
            if b.isdigit():
                user.save_money(int(b),atm)
            else:
                print("输入的不是数字请重新輸入")
        elif number2 == '3':
            user.show_money()
        elif number2 == '4':
            break




while 1:
    print("欢饮进入atm系统".center(30, '*'))
    print("1.atm\n2.用户\n3.退出")
    number = input("请输入数字：")
    if number == '1':
        print("atm")
        atm = ATM(10000, "工商银行", "农大")
        Atmenu()
        break
    elif number == '2':

        print("用户登录")
        name = input("用户名:")
        passwd = input("密码:")
        user = User(name,passwd,0)
        Usermenu()
        break
    elif number == '3':
        exit()
# atm1.add_money(60000)
# print(atm1.money)
# atm2.take_money(20000)
# print(atm2.money)
# user1.get_money(1000,atm1)
# print(atm1.money)
# user1.show_money()
#
#
# atm2 = ATM(20000,"nongye银行","农大")

